package dao;

import douban.DouBanContent;
import model.Aws_question;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created by liuyaowen on 2016/8/26.
 */
public class JdbcDemo {
     private static final Logger logger = LoggerFactory.getLogger(JdbcDemo.class);

    static ApplicationContext context = new ClassPathXmlApplicationContext("classpath:Beans.xml");
    public static void  save_aws_question(DouBanContent awsQuestion) {

        synchronized(JdbcDemo.class){
            DoubanJDBCTemplate jdbcTemplate =(DoubanJDBCTemplate)context.getBean("doubanJDBCTemplate");

            //该问题是否存在 存在则不插入
            if (!jdbcTemplate.check_aws_question(awsQuestion.getTitle())){
                //保存问题
                if (jdbcTemplate.insert_aws_question(awsQuestion)){
                    logger.info("insert_aws_question==is ok==>>>"+awsQuestion.getTitle());
                }
            }else{
                logger.info("it's question is existence["+awsQuestion.getTitle()+"]");
            }
        }

    }

    public static void main(String[] args) {
        DouBanContent awsQuestion=new DouBanContent();
        awsQuestion.setTitle("李依桐");
        awsQuestion.setContent("李依桐");
        awsQuestion.setCategory_id("2");
        JdbcDemo.save_aws_question(awsQuestion);
        JdbcDemo.save_aws_question(awsQuestion);
        JdbcDemo.save_aws_question(awsQuestion);
    }
}

